﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;
using HZ.Supervise.Model.Enum;
using HZ.Supervise.Model.View;
namespace HZ.Supervise.Web.Secondphase.Statistics
{
    public partial class HospitalPurchasePlanByHospital : BasePage
    {
       
 
        IExecuteContext iec = HZ.Supervise.BLLFactory.ExecuteContext();

        public HospitalPurchasePlanByHospital()
        {

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {  
                BindData();
            }
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager_CompanyPS_PageChanged(object sender, EventArgs e)
        { 
            BindData();

        }

        /// <summary>
        /// 绑定数据
        /// modify  by张雄  2011.5.4
        /// </summary>
        public void BindData()
        {
            SuperviseQuery vs = new SuperviseQuery();
            vs = Queryby();
            lblTitle.Text = string.Format(@"流水号:{4}； 通用名:{0}； 剂型:{1}； 包装:{2}；生产企业:{3}；", vs.ProductName, vs.MedicineModelName, vs.Pack, vs.CompanyName_SC, vs.ProcureCatalogID);
            int t = 0;
            System.Data.DataTable dt = iec.GetHospitalPurchasePlanByHospital(vs, this.AspNetPager_CompanyPS.CurrentPageIndex, AspNetPager_CompanyPS.PageSize, out t);
            AspNetPager_CompanyPS.RecordCount = t;

            this.gvwPSLInfo.PageSize = AspNetPager_CompanyPS.PageSize;
            this.gvwPSLInfo.DataSource = dt;
            this.gvwPSLInfo.DataBind();



        }
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager_CompanyPS.CurrentPageIndex = 1;
        }
        



        /// <summary>
        /// 导出 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            SuperviseQuery vs = new SuperviseQuery();
            vs = Queryby();
            int t = 0;
            System.Data.DataTable dt = iec.GetHospitalPurchasePlanByHospital(vs, 1, 0, out t);
            ExportFile.Instance.ExportData(dt, gvwPSLInfo, this.Page);
        }



        /// <summary>
        /// 查询条件
        /// </summary>
        /// <returns></returns>
        private SuperviseQuery Queryby()
        {
            SuperviseQuery vs = new SuperviseQuery(); 
            vs = (SuperviseQuery)Session[Request.QueryString["sesid"]];

            if (!string.IsNullOrEmpty(vs.HospitalName))
            {
                txtHospitalName.Text = vs.HospitalName;
            }
            if (!string.IsNullOrEmpty(txtHospitalName.Text.Trim()))
            {
                vs.HospitalName = txtHospitalName.Text.Trim();
            }
            else
            { vs.HospitalName = null; }
            vs.SortFields = ddlSortFields.SelectedValue + " " + ddlSort.SelectedValue;
            return vs;
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            string url = "HospitalPurchasePlan.aspx";

            Response.Redirect(url);
        }
        
    }

}

